package com.pmcc.core.entity.security;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pmcc.core.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * Created by syk on 17/6/23.
 */
@MappedSuperclass
@Getter
@Setter
public abstract class Authenticatable extends BaseEntity {
    /**
     * passphrase value
     */
    @Size(min = 4, max = 100)
    @JsonIgnore
    private String password;

    /**
     * The timestamp that last successfully login
     */
    @Column(nullable = false, length = 120)
    protected Date lastLoginDate;

    /**
     * The time that this guy registered, the value is immutable
     */
    @Column(nullable = false, updatable = false)
    protected Date registerDate;

    /**
     * 账户是否可以用.
     *
     * 用于封禁账户或类似功能
     */
    @Column(nullable = true)
    protected boolean enabled;

    /**
     * indicate whether the entity need to change its password on login
     */
    @Column()
    protected boolean needChangePassword;


    @javax.persistence.Temporal(TemporalType.TIMESTAMP)
    private Date lastPasswordResetDate;

    /**
     * Setup when the entity been created.
     *
     * We setup the registerDate here.
     */
    @PrePersist
    private void setup() {
        this.registerDate = new Date();
    }
}
